package com.genokon.consumer.controller;

import com.genokon.consumer.service.EchoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author by baichaoda
 * @Date 2020/7/22 15:32
 */
@RestController
public class TestController {
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private EchoService echoService;

    @GetMapping("/index")
    public String index(){
        return restTemplate.getForObject("http://service-provider", String.class);
    }

    @GetMapping("/test")
    public String test(){
        return restTemplate.getForObject("http://service-provider/test", String.class);
    }

    @GetMapping("/sleep")
    public String sleep(){
        return restTemplate.getForObject("http://service-provider/sleep", String.class);
    }

    @GetMapping("/echo-rest/{str}")
    public String rest(@PathVariable("str") String str){
        return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
    }

    @GetMapping("/echo-feign/{str}")
    public String echoFeign(@PathVariable("str") String str){
        return echoService.echo(str);
    }
}
